{% extends 'layouts/master.html' %}

{% set page = 'commits' %}

{% block title %}Gitamin{% endblock %}

{% block breadcrumb %}
    {% include 'partials/breadcrumb.html' with {breadcrumbs: [{dir: "Commit #{commit.hash}", path:''}]} %}
{% endblock %}

{% block content %}

    <div class="commit-view">
        <div class="commit-header">
            <span class="pull-right"><a class="btn btn-small" href="{{ route('branch', {owner: owner.slug, project: project.slug, branch: commit.hash}) }}" title="Browse code at this point in history"><i class="icon-list-alt"></i> Browse code</a></span>
            <h4>{{ commit.message }}</h4>
        </div>
        <div class="commit-body">
            {% if commit.body is not empty %}
            <p>{{ commit.body | nl2br }}</p>
            {% endif %}
            <img src="" class="pull-left space-right" />
            <span>
                <a href="mailto:{{ commit.author.email }}">{{ commit.author.name }}</a> authored on {{ commit.date | format_date }}
                {% if commit.author.email != commit.commiter.email %}
                &bull; <a href="mailto:{{ commit.commiter.email }}">{{ commit.commiter.name }}</a> committed on  {{ commit.commiterDate | format_date }}
                {% endif %}
                <br />Showing {{ commit.changedFiles }} changed files
            </span>
        </div>
    </div>

    <ul class="commit-list">
        {% for diff in commit.diffs %}
            <li><i class="icon-file"></i> <a href="#diff-{{ loop.index }}">{{ diff.file }}</a> <span class="meta pull-right">{{ diff.index }}</span></li>
        {% endfor %}
    </ul>

    {% for diff in commit.diffs %}
    <div class="source-view">
        <div class="source-header">
            <div class="meta"><a id="diff-{{ loop.index }}">{{ diff.file }}</div>

            <div class="btn-group pull-right">
                <a href="{{ route('commits', {owner: owner.slug, project: project.slug, commitishPath: commit.hash ~ '/' ~ diff.file}) }}" class="btn btn-small"><i class="icon-list-alt"></i> History</a>
                <a href="{{ route('blob', {owner: owner.slug, project: project.slug, commitishPath: commit.hash ~'/' ~ diff.file}) }}" class="btn btn-small"><i class="icon-file"></i> View file @ {{ commit.shortHash }}</a>
            </div>
        </div>

        <div class="source-diff">
        <table>
        {% for line in diff.getLines %}
            <tr>
                <td class="lineNo">
                    {% if line.getType != 'chunk' %}
                        <a name="L{{ loop.index }}R{{ line.getNumOld }}"></a>
                        <a href="#L{{ loop.index }}R{{ line.getNumOld }}">
                    {% endif %}
                    {{ line.getNumOld }}
                    {% if line.getType != 'chunk' %}
                        </a>
                    {% endif %}
                </td>
                <td class="lineNo">
                    {% if line.getType != 'chunk' %}
                        <a name="L{{ loop.index }}L{{ line.getNumNew }}"></a>
                        <a href="#L{{ loop.index }}L{{ line.getNumNew }}">
                    {% endif %}
                    {{ line.getNumNew }}
                    {% if line.getType != 'chunk' %}
                        </a>
                    {% endif %}
                </td>
                <td style="width: 100%">
                    <pre{% if line.getType %} class="{{ line.getType }}"{% endif %}>{{ line.getLine }}</pre>
                </td>
            </tr>
        {% endfor %}
        </table>
        </div>
    </div>
    {% endfor %}

{% endblock %}
